package edu.hebeu.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sun.tools.internal.ws.processor.model.Request;
import edu.hebeu.entity.Employee;
import edu.hebeu.entity.Employee2;
import edu.hebeu.mapper.EmployeeMapper;
import edu.hebeu.service.EmployeeService;
import edu.hebeu.util.MTimeUtil;
import jdk.nashorn.internal.ir.RuntimeNode;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.util.List;

/**
 * (Employee)表控制层
 *
 * @author makejava
 * @since 2024-12-05 14:59:54
 */
@Controller
@RequestMapping("employee")
public class EmployeeController {
    /**
     * 服务对象
     */
    @Resource
    private EmployeeService employeeService;
    @Autowired
    private EmployeeMapper employeeMapper;

    //首页
    @RequestMapping("/login.do")
    public String login() {
        return "login";
    }

    //登录接口
    @RequestMapping(value = "/checkLogin.do")
    public String checklogin(Employee2 employee2, HttpSession session) {
        Employee employee1 = employeeService.selectcheck(employee2.getEmployeeNumber(), employee2.getPassword());
        if (employee1 != null) {
            session.setAttribute("loged", employee1);
            return "admin/index1";
        }
        return "login";
    }

    //注销登录
    @RequestMapping("/logout.do")
    public String logout() {

        return "login";
    }

    //主页
    @RequestMapping("/welcome.do")
    public String welcome() {
        return "welcome";
    }

    //查看个人信息
    @RequestMapping("/oneself/{id}/detial.do")
    public String detail(@PathVariable Integer id, Model model) {
        Employee employee = employeeService.select(id);
        model.addAttribute("employee", employee);
        return "admin/oneself_detail";
    }

    //修改个人信息的查询
    @RequestMapping("/oneself/{id}/toUpdate.do")
    public String toUpdate(@PathVariable Integer id, Model model) {
        Employee employee = employeeService.selectById(id);
        // Employee employee = employeeMapper.selectId(id);
        model.addAttribute("employee", employee);
        return "admin/oneself_update";
    }

    //修改个人信息的修改
    @RequestMapping("/oneself/{id}/update.do")
    public String update(@PathVariable Integer id, Model model, Employee employee, String date) {
        employee.setBirthday(MTimeUtil.stringParse(date));
        employee.setId(id);
        //employeeService.updateById(employee);
        employeeMapper.updateBy(employee);
      /* model.addAttribute("employee",employee);
       return "admin/oneself_update";*/
        /*Employee employee1 = employeeService.select(id);
      model.addAttribute("employee",employee1);
        return "admin/oneself_detail";*/
        //return "forward:/employee/oneself/{id}/detial.do";
        return "forward:/employee/oneself/{id}/toUpdate.do";
    }

    @RequestMapping("/listPage.do")
    public String selectIncumbency(@RequestParam int pageNo, Model model) {
        model.addAttribute("page", employeeService.selectIncumbency(pageNo));
        return "admin/employee_list";
    }


}

